-- toolchains/mygcc14.lua
toolchain("mygcc14", function()
    set_kind("standalone")
    set_description("GCC 14.2.0 + CUDA 12.9")

    -------------------------------------------------
    -- 1) 指定编译器 / 汇编器 / 归档器
    -------------------------------------------------
    local gcc_root = "$(env HOME)/cpplibs/gcc-14.2.0"
    set_toolset("cc", gcc_root .. "/bin/gcc")
    set_toolset("cxx", gcc_root .. "/bin/g++")
    set_toolset("ld", gcc_root .. "/bin/g++") -- ld for linking executable
    set_toolset("sh", gcc_root .. "/bin/g++") -- sh for shared library
    -- set_toolset("ld",   "/usr/bin/mold")
    -- set_toolset("sh",   "/usr/bin/mold") -- 使用 mold 链接器加快链接速度
    set_toolset("ar", gcc_root .. "/bin/gcc-ar")
    set_toolset("ranlib", gcc_root .. "/bin/gcc-ranlib")
    set_toolset("as", gcc_root .. "/bin/gcc")            -- assembler

    set_toolset("cu", "/usr/local/cuda-12.9/bin/nvcc")   -- CUDA compiler
    set_toolset("culd", "/usr/local/cuda-12.9/bin/nvcc") -- CUDA linker

    -------------------------------------------------
    -- 2) 头文件 / 库搜索路径
    -------------------------------------------------
    add_includedirs(gcc_root .. "/include")
    add_linkdirs(gcc_root .. "/lib64")
    add_linkdirs("/usr/local/cuda-12.9/lib64")

    -------------------------------------------------
    -- 3) CUDA 专用设置（仅 nvcc 可见）
    -------------------------------------------------
    on_load(function(toolchain)
        -- 只对 nvcc 生效
        toolchain:add("cuflags", "-ccbin=" .. gcc_root .. "/bin/gcc")
        toolchain:add("sysincludedirs", "/usr/local/cuda-12.9/include")
    end)
end)
